<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
    // This tests for a bug in GMail's Editor, they try to extract the contents
    // of a range that has had it's contents removed from the document by an
    // editing command.  Since the bug 43017 requires WebKit does not remove
    // anchor elements, div should be empty after the extraction. We currently
    // leave anchor element in the div due to the Bug 47916.
    test(() => assert_selection(
        [
            '<div contenteditable id="div" >',
                '|dog<a href="http://example.com/">food</a>',
            '</div>',
        ].join(''),
        selection => {
            selection.document.execCommand('selectAll');
            selection.document.execCommand('removeFormat');
        },
        [
            '<div contenteditable id="div">',
                '^dog<a href="http://example.com/">food|</a>',
            '</div>',
        ].join('')),
        'removeFormat command should not remove A element.');

    test(() => assert_selection(
        [
            '<div contenteditable id="div" >',
                '|dog<a href="http://example.com/">food</a>',
            '</div>',
        ].join(''),
        selection => {
            var div = selection.document.getElementById("div");
            var text = div.firstChild;
            var link = div.lastChild;
            div.focus();

            var range = selection.document.createRange();
            range.setStart(text, 0);
            range.setEnd(link, link.childNodes.length);

            selection.document.execCommand('selectAll');
            selection.document.execCommand('removeFormat');
            var result = range.extractContents();
            var element = selection.document.createElement('div');
            element.appendChild(result);
            assert_equals(element.innerHTML,
                'dog<a href="http://example.com/">food</a>');
        },
        [
            '<div contenteditable id="div">',
                '|<a href="http://example.com/"></a>',
            '</div>',
        ].join('')),
        'Range#extractContents() extracts A with anchor text but leaves A.');
</script>
